/**
 * 订单管理 交易订单
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>交易订单</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <el-form-item label="搜索：">
        <el-input size="small" v-model="formInline.poNo" placeholder="输入订单编号"></el-input>
      </el-form-item>
      <el-form-item label="app客户账号">
        <el-input size="small" v-model="formInline.auUsername" placeholder="输入app客户账号"></el-input>
      </el-form-item>
      <el-form-item label="按照订单时间查询-时间下限">
        <el-date-picker v-model="formInline.poStart" type="date" placeholder="选择日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="按照订单时间查询-时间上限">
        <el-date-picker v-model="formInline.poEnd" type="date" placeholder="选择日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="订单支付状态">
        <el-select size="small" v-model="formInline.poState" placeholder="请选择">
          <el-option v-for="type in payState" :label="type.key" :value="type.value" :key="type.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column align="center" type="index" width="60">
      </el-table-column>
      <el-table-column sortable prop="poNo" label="订单编号" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="parkingLotVO.plName" label="停车场信息" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="appUserVO.auUsername" label="app客户账号" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="poPrice" label="单价" width="140" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="poStart" label="开始时间" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="poEnd" label="结束时间" width="120" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="poState" label="订单状态" width="180" :formatter="formatState" show-overflow-tooltip>
      </el-table-column>
      <el-table-column align="center" label="操作" min-width="150">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">预览</el-button>
          <span v-if="scope.row.poState==1">
            <el-button size="mini" type="danger" @click="orderRefund(scope.$index, scope.row)">退款</el-button>
          </span>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
    <!-- 详情界面 -->
    <el-dialog :title="title" :visible.sync="editFormVisible" width="50%" @click="closeDialog('editForm')">
      <el-form label-width="120px" :model="editForm" ref="editForm">
        <el-row>
          <el-col :span="12">
            <el-form-item label="订单编号">
              <el-input size="small" v-model="editForm.poNo" auto-complete="off" placeholder="请输入名称" disabled></el-input>
            </el-form-item>
            <el-form-item label="停车场信息-名称">
              <el-input size="small" v-model="editForm.parkingLotVO.plName" auto-complete="off" placeholder="" disabled></el-input>
            </el-form-item>
            <el-form-item label="停车场信息-地址">
              <el-input size="small" v-model="editForm.parkingLotVO.plAddress" auto-complete="off" placeholder="" disabled></el-input>
            </el-form-item>
            <el-form-item label="app客户账号">
              <el-input size="small" v-model="editForm.appUserVO.auUsername" auto-complete="off" placeholder="" disabled></el-input>
            </el-form-item>
            <el-form-item label="app客户昵称">
              <el-input size="small" v-model="editForm.appUserVO.auNickname" auto-complete="off" placeholder="" disabled></el-input>
            </el-form-item>
            <el-form-item label="单价">
              <el-input size="small" v-model="editForm.poPrice" auto-complete="off" placeholder="" disabled></el-input>
            </el-form-item>
            <el-form-item label="开始时间">
              <el-input size="small" v-model="editForm.poStart" auto-complete="off" placeholder="" disabled></el-input>
            </el-form-item>
            <el-form-item label="结束时间">
              <el-input size="small" v-model="editForm.poEnd" auto-complete="off" placeholder="" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="备注">
          <el-input size="small" v-model="editForm.remark" auto-complete="off" placeholder="" disabled></el-input>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import {OrderList, OrderRefund, OrderDelete, ParkingOrderList,orderRefund} from '../../api/payMG'
import Pagination from '../../components/Pagination'
export default {
  data() {
    return {
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: '预览',
      priceArea: [
        { key: '请选择', value: null },
        { key: '大于此价格', value: 1 },
        { key: '小于此价格', value: 2 },
        { key: '等于此价格', value: 3 },
      ],
      payState: [
        { key: '请选择', value: 0 },
        { key: '待支付', value: 0 },
        { key: '已支付', value: 1 },
      ],
      editForm: {
        poNo:null,
        parkingLotVO:{
          plName:null,
          plAddress:null,
        },
        appUserVO:{
          auUsername:null,
          auNickname:null,
        },
        poPrice:null,
        poStart:null,
        poEnd:null,


        token: localStorage.getItem('logintoken')
      },
      formInline: {
        page: 1,
        limit: 5,
        plName: null,
        auUsername: null,
        poState: "",
        // token: localStorage.getItem('logintoken')
      },
      // 删除部门
      seletedata: {
        ids: '',
        token: localStorage.getItem('logintoken')
      },
      userparm: [], //搜索权限
      listData: [], //用户数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 5,
        total: null
      }
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    this.getdata(this.formInline)
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {

    formatState(row, column, cellValue, index){
      return cellValue == 0 ? "待支付" : "已支付";
    },
    // 获取停车场订单列表
    getdata(parameter) {
      /***
       * 调用接口，注释上面模拟数据 取消下面注释
       */

      ParkingOrderList(parameter).then(result => {
          this.loading = false
          console.log("order:",result);
          if (result.code==1) {
            this.$message({
              type: 'info',
              message: res.msg
            })
          } else if (result.code==0) {
            this.listData = result.data.list
            // 分页赋值
            this.pageparm.currentPage = result.data.pageNum;
            this.pageparm.pageSize = result.data.pageSize
            this.pageparm.total = result.data.total
          } else {
            this.$message({
              type: 'info',
              message: result.msg
            })
          }
        }).catch(err => {
          this.loading = false
          this.$message.error('菜单加载失败，请稍后再试！')
        })
    },

    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage
      this.formInline.limit = parm.pageSize
      this.getdata(this.formInline)
    },

    // 搜索事件
    search() {
      this.getdata(this.formInline)
    },

    //显示编辑界面
    handleEdit: function(index, row) {
      console.log("row==",row)
      this.editFormVisible = true
      this.editForm = row
    },

    // 编辑、增加页面保存方法
    submitForm(editData) {
      this.$refs[editData].validate(valid => {
        if (valid) {
          ConfigSave(this.editForm)
            .then(res => {
              this.editFormVisible = false
              this.loading = false
              if (res.success) {
                this.getdata(this.formInline)
                this.$message({
                  type: 'success',
                  message: '公司保存成功！'
                })
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.editFormVisible = false
              this.loading = false
              this.$message.error('支付配置信息保存失败，请稍后再试！')
            })
        } else {
          return false
        }
      })
    },
    // 订单退款
    orderRefund(index, row) {
      this.$confirm('确定要退款吗?', '信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        console.log("row=",row)
        orderRefund(row.poNo).then(res => {
              if (res.code==0) {
                this.$message({
                  type: 'success',
                  message: '退款成功!'
                })
                this.getdata(this.formInline)
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            }).catch(err => {
              this.loading = false
              this.$message.error('退款失败，请稍后再试！')
            })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消退款'
          })
        })
    },
    // 关闭编辑、增加弹出框
    closeDialog(formName) {
      this.editFormVisible = false
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
</style>




